package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaAdminBus;
import com.ruoyi.oa.domain.vo.OaAdminBusVo;
import com.ruoyi.oa.domain.bo.OaAdminBusBo;
import com.ruoyi.oa.service.IOaAdminBusService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.oa.domain.vo.OaProjectVo;


/**
 * 私车公用申请
 *
 * @author ruoyi
 * @date 2023-08-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/adminBus")
public class OaAdminBusController extends BaseController {

    private final IOaAdminBusService iOaAdminBusService;

    /**
     * 查询私车公用申请列表
     */
//    @SaCheckPermission("oa:adminBus:list")
    @GetMapping("/list")
    public TableDataInfo<OaAdminBusVo> list(OaAdminBusBo bo, PageQuery pageQuery) {
        return iOaAdminBusService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出私车公用申请列表
     */
//    @SaCheckPermission("oa:adminBus:export")
    @Log(title = "私车公用申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaAdminBusBo bo, HttpServletResponse response) {
        List<OaAdminBusVo> list = iOaAdminBusService.queryList(bo);
        ExcelUtil.exportExcel(list, "私车公用申请", OaAdminBusVo.class, response);
    }

    /**
     * 获取私车公用申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:adminBus:query")
    @GetMapping("/{id}")
    public R<OaAdminBusVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaAdminBusService.queryById(id));
    }

    /**
     * 新增私车公用申请
     */
//    @SaCheckPermission("oa:adminBus:add")
    @Log(title = "私车公用申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaAdminBusBo> add(@Validated(AddGroup.class) @RequestBody OaAdminBusBo bo) {
        return R.ok(iOaAdminBusService.insertByBo(bo));
    }

    /**
     * 修改私车公用申请
     */
//    @SaCheckPermission("oa:adminBus:edit")
    @Log(title = "私车公用申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaAdminBus> edit(@Validated(EditGroup.class) @RequestBody OaAdminBusBo bo) {
        return R.ok(iOaAdminBusService.updateByBo(bo));
    }

    /**
     * 删除私车公用申请
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("oa:adminBus:remove")
    @Log(title = "私车公用申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaAdminBusService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
